package com.example.zhiran.controller;

import com.example.zhiran.pojo.front.FrontTag;
import com.example.zhiran.pojo.option.OptionResult;
import com.example.zhiran.pojo.orm.ZRTag;
import com.example.zhiran.service.tagservice.ZRTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin("localhost:8081/")
@RestController
@RequestMapping("tag")
public class ZRTagController {
    @Autowired
    ZRTagService tagService;

    @GetMapping("/getTags")
    public OptionResult getAllTags(){
        return tagService.getAllTags();
    }

    @GetMapping(value = "getTags",params = {"ctyId"})
    public OptionResult getTagsByCategoryId(@RequestParam(name = "ctyId") int ctyId){
        return tagService.getTagsByCategoryId(ctyId);
    }

    @PostMapping("/addTag")
    @ResponseBody
    public OptionResult addTag(FrontTag tag){
        return tagService.addTag(tag);
    }

    @PutMapping("/updateTag")
    @ResponseBody
    public OptionResult updateTag(ZRTag zrTag){
        return tagService.updateTag(zrTag);
    }

    @DeleteMapping("/deleteTag")
    public OptionResult deleteTag(int tagId){
        return tagService.deleteTag(tagId);
    }
}
